package utility;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.FileInputStream;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.JPanel;

public class PieceImage extends JPanel{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private BufferedImage img;
	private int dWidth;
	private int dHeight;
	public PieceImage(String path) {
		this.setOpaque(false);
			try {
				this.img = ImageIO.read(new FileInputStream(path));
				dWidth = img.getWidth();
				dHeight = img.getHeight();
			} catch (IOException ex) {
				ex.printStackTrace();
			}
	}
	@Override
	protected void paintComponent(Graphics g) {
		super.paintComponent(g); 
			g.drawImage(img, 0, 0, img.getWidth(), img.getHeight(), this);

	}
	@Override
	public Dimension getPreferredSize() {
		return (img == null) ? new Dimension(100, 100) : new Dimension(dWidth, dHeight);
	}
}
